package com.xianbeiying.app.ckgl.activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xianbeiying.app.ckgl.R;
import com.xianbeiying.app.ckgl.bean.DpWatherBean;
import com.xianbeiying.app.ckgl.util.DataUtil;

/**
 * 天数数据的展示
 */
public class WeatherActivity extends BaseActivity {

    private LinearLayout ly_horizontal;
    //返回控件
    private ImageView iv_title_left;
    //标题
    private TextView tv_title;
    private TextView tv_city;
    private TextView tv_sheshidu;
    private TextView tv_weather;
    private TextView tv_content;

    private DpWatherBean dpWatherBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_weather);
        initView();
    }

    private void initView() {
        tv_city = (TextView) findViewById(R.id.tv_city);
        tv_sheshidu = (TextView) findViewById(R.id.tv_sheshidu);
        tv_weather = (TextView) findViewById(R.id.tv_weather);
        tv_content = (TextView) findViewById(R.id.tv_content);
        ly_horizontal = (LinearLayout) findViewById(R.id.ly_horizontal);
        //标题
        tv_title = (TextView) findViewById(R.id.tv_title);
        //返回控件
        iv_title_left = (ImageView) findViewById(R.id.iv_title_left);
        initData();
        initEvent();
    }

    private void initData() {
        dpWatherBean = (DpWatherBean) getIntent().getSerializableExtra("dpWatherBean");
        if (dpWatherBean == null) {
            return;
        }
        tv_city.setText(dpWatherBean.getData().getCity());
        tv_sheshidu.setText(dpWatherBean.getData().getWendu() + "℃");
        tv_weather.setText(dpWatherBean.getData().getForecast().get(0).getType());
        tv_content.setText(dpWatherBean.getData().getGanmao());
        tv_title.setText("天气");
        int size = dpWatherBean.getData().getForecast().size();
        for (int i = 0; i < size; i++) {
            //每个textview的宽度
            View view = LayoutInflater.from(this).inflate(R.layout.item_weather, null);
            TextView tv_today = (TextView) view.findViewById(R.id.tv_today);
            TextView tv_temp = (TextView) view.findViewById(R.id.tv_temp);
            TextView tv_weather = (TextView) view.findViewById(R.id.tv_weather);
            ImageView iv_weather = (ImageView) view.findViewById(R.id.iv_weather);
            tv_today.setText(DataUtil.getRQs(dpWatherBean.getData().getForecast().get(i).getDate(),i));
            int max = Integer.valueOf(DataUtil.getTemp(dpWatherBean.getData().getForecast().get(i).getHigh(), "高温", "℃"));
            int min = Integer.valueOf(DataUtil.getTemp(dpWatherBean.getData().getForecast().get(i).getLow(), "低温", "℃"));
            tv_temp.setText(min + "/" + max + "℃");
            tv_weather.setText(dpWatherBean.getData().getForecast().get(i).getType());
            setImage(dpWatherBean.getData().getForecast().get(i).getType(), iv_weather);
            ly_horizontal.addView(view);
        }
    }

    private void initEvent() {
        iv_title_left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    public void setImage(String mark, ImageView imageView) {
//        boolean b1 = getString(mark, "多云");
//        if (b1) {
//            mark = "多云";
//        }
        switch (mark) {
            case "晴": {
                imageView.setImageResource(R.mipmap.qings);
                break;
            }
            case "多云": {
                imageView.setImageResource(R.mipmap.duoyuns);
                break;
            }
            case "阴": {
                imageView.setImageResource(R.mipmap.yins);
                break;
            }
            case "阵雨": {
                imageView.setImageResource(R.mipmap.zhenyus);
                break;
            }
            case "雷阵雨": {
                imageView.setImageResource(R.mipmap.leizhenyus);
                break;
            }
            case "雷阵雨伴有冰雹": {
                imageView.setImageResource(R.mipmap.leizhenyubanyoubingbaos);
                break;
            }
            case "雨夹雪": {
                imageView.setImageResource(R.mipmap.yujiaxues);
                break;
            }
            case "小雨": {
                imageView.setImageResource(R.mipmap.xiaoyus);
                break;
            }
            case "中雨": {
                imageView.setImageResource(R.mipmap.zhongyus);
                break;
            }
            case "暴雨": {
                imageView.setImageResource(R.mipmap.baoxues);
                break;
            }
            case "大暴雨": {
                imageView.setImageResource(R.mipmap.dabaoyus);
                break;
            }
            case "特大暴雨": {
                imageView.setImageResource(R.mipmap.tedabaoyus);
                break;
            }
            case "阵雪": {
                imageView.setImageResource(R.mipmap.zhenxues);
                break;
            }
            case "小雪": {
                imageView.setImageResource(R.mipmap.xiaoxues);
                break;
            }
            case "中雪": {
                imageView.setImageResource(R.mipmap.zhongxues);
                break;
            }
            case "大雪": {
                imageView.setImageResource(R.mipmap.daxues);
                break;
            }
            case "暴雪": {
                imageView.setImageResource(R.mipmap.baoxues);
                break;
            }
            case "雾": {
                imageView.setImageResource(R.mipmap.wus);
                break;
            }
            case "冻雨": {
                imageView.setImageResource(R.mipmap.dongyus);
                break;
            }
            case "沙尘暴": {
                imageView.setImageResource(R.mipmap.shachenbaos);
                break;
            }
            case "小雨-中雨": {
                imageView.setImageResource(R.mipmap.xiaoyu_zhongyus);
                break;
            }
            case "中雨-大雨": {
                imageView.setImageResource(R.mipmap.zhongyu_dayus);
                break;
            }
            case "大雨-暴雨": {
                imageView.setImageResource(R.mipmap.dayu_baoyus);
                break;
            }
            case "暴雨-大暴雨": {
                imageView.setImageResource(R.mipmap.baoyu_dabaoyus);
                break;
            }
            case "大暴雨-特大暴雨": {
                imageView.setImageResource(R.mipmap.dabaoyu_tedabaoyus);
                break;
            }
            case "小雪-中雪": {
                imageView.setImageResource(R.mipmap.xiaoxue_zhongxues);
                break;
            }
            case "中雪-大雪": {
                imageView.setImageResource(R.mipmap.zhongxue_daxues);
                break;
            }
            case "大雪-暴雪": {
                imageView.setImageResource(R.mipmap.daxue_baoxues);
                break;
            }
            case "扬沙": {
                imageView.setImageResource(R.mipmap.yangshas);
                break;
            }
            case "强沙尘暴": {
                imageView.setImageResource(R.mipmap.qiangshachenbaos);
                break;
            }
            case "霾": {
                imageView.setImageResource(R.mipmap.mais);
                break;
            }
            default:
                imageView.setImageResource(R.mipmap.qings);
                break;
        }
    }
}
